<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Call a static method and pass the arguments as array</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.create-function.html">create_function</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.forward-static-call.html">forward_static_call</a></div>
 <div class="up"><a href="ref.funchand.html">Function handling 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.forward-static-call-array" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">forward_static_call_array</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.3.0)</p><p class="refpurpose"><span class="refname">forward_static_call_array</span> &mdash; <span class="dc-title">Call a static method and pass the arguments as array</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.forward-static-call-array-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><strong>forward_static_call_array</strong></span>
    ( <span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$function</code></span>
   , <span class="methodparam"><span class="type">array</span> <code class="parameter">$parameters</code></span>
   )</div>

  <p class="para rdfs-comment">
   Calls a user defined function or method given by the <em><code class="parameter">function</code></em>
   parameter. This function must be called within a method context, it can&#039;t be 
   used outside a class.
   It uses the <a href="language.oop5.late-static-bindings.html" class="link">late static
   binding</a>.
   All arguments of the forwarded method are passed as values,
   and as an array, similarly to <span class="function"><a href="function.call-user-func-array.html" class="function">call_user_func_array()</a></span>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.forward-static-call-array-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">function</code></em></dt>

     <dd>

      <p class="para">
       The function or method to be called. This parameter may be an <span class="type"><a href="language.types.array.html" class="type array">array</a></span>,
       with the name of the class, and the method, or a <span class="type"><a href="language.types.string.html" class="type string">string</a></span>, with a function
       name.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">parameter</code></em></dt>

     <dd>

      <p class="para">
       One parameter, gathering all the method parameter in one array.
      </p>
      <blockquote class="note"><p><strong class="note">Note</strong>: 
       <p class="para">
        Note that the parameters for <span class="function"><strong>forward_static_call_array()</strong></span> are
        not passed by reference.
       </p>
      </p></blockquote>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.forward-static-call-array-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns the function result, or <strong><code>FALSE</code></strong> on error.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.forward-static-call-array-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-5009">
    <p><strong>Example #1 <span class="function"><strong>forward_static_call_array()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">A<br /></span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;const&nbsp;</span><span style="color: #0000BB">NAME&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'A'</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;function&nbsp;</span><span style="color: #0000BB">test</span><span style="color: #007700">()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$args&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">func_get_args</span><span style="color: #007700">();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;static::</span><span style="color: #0000BB">NAME</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"&nbsp;"</span><span style="color: #007700">.</span><span style="color: #0000BB">join</span><span style="color: #007700">(</span><span style="color: #DD0000">','</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$args</span><span style="color: #007700">).</span><span style="color: #DD0000">"&nbsp;\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br />class&nbsp;</span><span style="color: #0000BB">B&nbsp;</span><span style="color: #007700">extends&nbsp;</span><span style="color: #0000BB">A<br /></span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;const&nbsp;</span><span style="color: #0000BB">NAME&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'B'</span><span style="color: #007700">;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;function&nbsp;</span><span style="color: #0000BB">test</span><span style="color: #007700">()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">self</span><span style="color: #007700">::</span><span style="color: #0000BB">NAME</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">forward_static_call_array</span><span style="color: #007700">(array(</span><span style="color: #DD0000">'A'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'test'</span><span style="color: #007700">),&nbsp;array(</span><span style="color: #DD0000">'more'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'args'</span><span style="color: #007700">));<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">forward_static_call_array</span><span style="color: #007700">(&nbsp;</span><span style="color: #DD0000">'test'</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #DD0000">'other'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'args'</span><span style="color: #007700">));<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /></span><span style="color: #0000BB">B</span><span style="color: #007700">::</span><span style="color: #0000BB">test</span><span style="color: #007700">(</span><span style="color: #DD0000">'foo'</span><span style="color: #007700">);<br /><br />function&nbsp;</span><span style="color: #0000BB">test</span><span style="color: #007700">()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$args&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">func_get_args</span><span style="color: #007700">();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"C&nbsp;"</span><span style="color: #007700">.</span><span style="color: #0000BB">join</span><span style="color: #007700">(</span><span style="color: #DD0000">','</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$args</span><span style="color: #007700">).</span><span style="color: #DD0000">"&nbsp;\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
B
B more,args 
C other,args
</pre></div>
    </div>
   </div>
  </p>
 </div>

 
 <div class="refsect1 seealso" id="refsect1-function.forward-static-call-array-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.forward-static-call.html" class="function" rel="rdfs-seeAlso">forward_static_call()</a> - Call a static method</span></li>
    <li class="member"><span class="function"><a href="function.call-user-func.html" class="function" rel="rdfs-seeAlso">call_user_func()</a> - Call the callback given by the first parameter</span></li>
    <li class="member"><span class="function"><a href="function.call-user-func-array.html" class="function" rel="rdfs-seeAlso">call_user_func_array()</a> - Call a callback with an array of parameters</span></li>
    <li class="member"><span class="function"><a href="function.is-callable.html" class="function" rel="rdfs-seeAlso">is_callable()</a> - 检测参数是否为合法的可调用结构</span></li>
    <li class="member"><a href="language.pseudo-types.html#language.types.callback" class="link">callback</a> 类型的信息</li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.create-function.html">create_function</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.forward-static-call.html">forward_static_call</a></div>
 <div class="up"><a href="ref.funchand.html">Function handling 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
